package com.banksystem.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.banksystem.Util.TokenUtil;
import com.banksystem.entity.Liuyan;
import com.banksystem.service.Liuyanservice;

@Controller
public class lyglController {

	@Autowired
	private Liuyanservice ser;
	@Autowired
	private TokenUtil tokenUtil;
	
	/*
	 * 添加留言
	 */
	@RequestMapping("addly")
	public  String addly() {
		return "lygl/addly";
	}
	@RequestMapping("addlya")
	public @ResponseBody String addlya(String name,String title,String js){
		ser.addly(name, title, js);
		return "lyck.do";
	}
	/*
	 * 留言查看
	 */
	@RequestMapping("lyck")
	public String lyck(HttpServletRequest request,ModelMap model) {
		String gname = tokenUtil.findUsernameBytoken(request);
		List<Liuyan> list;
		if(gname.equals("admin")) {
			list=ser.adminfindliuyanall();
		}else {
			list=ser.findliuyanall(gname);
		}
		model.addAttribute("Liuyanlist", list);
		return "lygl/lyck";
	}
	/*
	 *删除
	 */
	@RequestMapping("deletely")
	public String deletely(String id){
		ser.deletely(id);
		return "forward:lyck.do";
	}
	/*
	 * 搜索
	 */
	@RequestMapping("seachly")
	public @ResponseBody List<Liuyan> seach(String seach,HttpServletRequest request) {
		String gname = tokenUtil.findUsernameBytoken(request);
		List<Liuyan> list=ser.findliuyanAlllike(seach, gname);
		return list;
	}
}
